<?

function exec_qry($query)
{
return mysql_query($query);
}


function qry_data($query)
{

	$dbr_queryResult=exec_qry($query);
	if ($dbr_queryResult) {
			 
	         
		        $int_resultCounter = 0;
	         	$arr_result = Array ();

	         	while ($arr_fetchedResult = @mysql_fetch_array ($dbr_queryResult)) {
	            	// remove slashes if needed
	            
	               		while (list ($mix_key, $mix_val) = each ($arr_fetchedResult)) {
	               			// if the value is a string, un-escape it
	                  		if (gettype ($mix_val) == "string" ) {
	                  			$arr_fetchedResult[$mix_key] = stripslashes($mix_val);
	                  		}
	               		}
	            
		            // create resulting array
		            $arr_result[$int_resultCounter] = $arr_fetchedResult;
		            $int_resultCounter ++;
		         }
		         
		         
		         return ($arr_result);
	}

}

function insert_qry($str_table,$arr_data)
{

      $bol_enclose=true;
      $arr_columns = qry_data("SHOW COLUMNS FROM ".$str_table."");

      $str_query = "INSERT INTO ".$str_table." SET ";
      foreach ($arr_columns as $arr_col) {
         if ($arr_data[$arr_col["Field"]]) {
             if ($bol_enclose)
                 $str_query .= $arr_col["Field"]."='".$arr_data[$arr_col["Field"]]."', ";
             else
                 $str_query .= $arr_col["Field"]."=".$arr_data[$arr_col["Field"]].", ";
         }
      }
      $str_query = substr($str_query, 0, -2);     // ", " abhacken
      exec_qry ( $str_query );
 
     return mysql_insert_id(); 

}

function enclose($strText)
{
return "'".$strText."'";

}
function update_qry($str_table,$arr_data,$str_where="")
{
	
	$bol_enclose=true;
	
	$arr_columns = qry_data("SHOW COLUMNS FROM ".$str_table."");
	
	$str_query = "UPDATE ".$str_table." SET ";
		foreach ($arr_columns as $arr_col) {
		if (isset($arr_data[$arr_col["Field"]])) {
			if ($bol_enclose) {
			$str_query .= $arr_col["Field"]."='".$arr_data[$arr_col["Field"]]."', ";
			} else {
			$str_query .= $arr_col["Field"]."=".$arr_data[$arr_col["Field"]].", ";
			}
		}
	}
	
      $str_query = substr($str_query, 0, -2);     // ", " abhacken

      $str_query .= " WHERE ( ".$str_where." )";

      exec_qry( $str_query );

}

function delete_qry($tblName,$where="")
{



}


function getMemberSIGNameList($memberId)
{


$sig_groups=Array("","PMO","IT Infrastructure","Project Collaboration tools","Helpdesk","Website Frontend","App dev & web scripts","Multimedia","IT industry service","Information Research");

$sigList=getMemberSIG($memberId);
$varList="";

foreach($sigList as $sig_id=>$sigStatus)
{
if($varList=="") 
$varList=$sig_groups[$sig_id];
else
$varList=$varList.",".$sig_groups[$sig_id];

}

return $varList;

}

function getMemberSIG($memberId)
{

$arr_info= qry_data("select sig_id from bkitc_member_sig where member_id=".$memberId);
$sigList=Array();
if(count($arr_info)>0) {
foreach($arr_info as $i=>$sig)
{
$sigList[$sig[0]]=1;

}
}
return $sigList;
}

function setMemberSIG($memberId,$sig_list)
{
	
	qry_data("delete from bkitc_member_sig where member_id=".$memberId);
	if(count($sig_list)>0) 	foreach($sig_list as $sigid) qry_data("insert into bkitc_member_sig(member_id,sig_id) values($memberId,$sigid)");

}




function generatePasswordForAll(){

exec_qry("UPDATE bkitc_profiles SET reg_password=substring(md5(concat('BKITC',LPAD(registrant_id,5,'0'))),1,5) where (reg_password IS NULL or reg_password='')");


}

function updateUserPassword($memberId,$password){

exec_qry("UPDATE bkitc_profiles SET reg_password='".$password."' WHERE registrant_id='".$memberId."'");
return 1;

}
function validateUser($vusername,$vpassword){

$userInfo=@array_pop(qry_data("select * from dev_user_mast where user_name='".$vusername."'"));

if($userInfo["user_name"]!=""){

	if($userInfo["password"]==$vpassword)
		return $userInfo;
	else 
		return 2;

}else{

return 1;

}

	

}

function getMemberInfo($memberId){

$memberInfo=qry_data("select * from bkitc_profiles where registrant_id=".$memberId);
return @array_pop($memberInfo);

}

function isMemberEmailExists($emailId){

$arr_info= qry_data("select * from bkitc_profiles where email_id='".$emailId."'"); 
$member_count=count($arr_info);
return $member_count;

}



?>

